import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/models/userinformodel.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/pages/addresspage/addrespage.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/pages/likepage/likepage.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/pages/orderpage/orderpage.dart';
import 'package:flutter_bmfmap_example/pages/marketpage/pages/shoppingCart/buyCar.dart';
import 'package:flutter_bmfmap_example/pages/minepage/pages/settingpage.dart';
import 'package:flutter_bmfmap_example/pages/minepage/pages/about.dart';
import 'package:flutter_bmfmap_example/pages/minepage/pages/agreementpage.dart';
import 'package:flutter_bmfmap_example/pages/minepage/pages/informationpage.dart';

import 'package:flutter_bmfmap_example/pages/rootpage.dart';
import 'package:provider/provider.dart';
// import 'package:flutter_bmfmap_example/service/userhepler.dart';
import 'package:url_launcher/url_launcher.dart';

// import 'about.dart';
// import 'informationpage.dart';

class MinePage extends StatefulWidget {
  MinePage({Key key}) : super(key: key);

  @override
  _MinePageState createState() => _MinePageState();
}

class _MinePageState extends State<MinePage>
    with SingleTickerProviderStateMixin {
  Animation<double> animation1;
  AnimationController _controller1;

  TextStyle t1 = TextStyle(
    fontSize: 22,
    color: Color.fromRGBO(112, 112, 112, 1),
    fontWeight: FontWeight.bold,
  );
  TextStyle t2 = TextStyle(
    fontSize: 10,
    color: Color.fromRGBO(112, 112, 112, 1),
    fontWeight: FontWeight.bold,
  );

  var tem = '0';
  var year = '0';
  var hum = '0';
  @override
  void initState() {
    super.initState();
    _getweather();

    _controller1 = new AnimationController(
        duration: const Duration(milliseconds: 1000), vsync: this);
    animation1 = new Tween(begin: 8.0, end: 20.0).animate(_controller1)
      ..addListener(() {
        setState(() {
          // the state that has changed here is the animation object’s value
        });
      });
    animation1.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        _controller1.reverse();
      } else if (status == AnimationStatus.dismissed) {
        _controller1.forward();
      }
    });
    // _controller1.forward();
  }

  _getweather() async {
    var response =
        await Http.get('http://t.weather.itboy.net/api/weather/city/101290101');
    year = response['time'].toString().split(' ')[0];
    tem = response['data']['wendu'];
    hum = response['data']['shidu'];
    if (mounted) {
      setState(() {});
    }
  }

  @override
  void dispose() {
    print("dispose");
    _controller1.stop();
    _controller1.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print('rebuild');
    return Material(
      child: Container(
        color: Color.fromRGBO(252, 230, 189, 1),
        child: Stack(
          children: [
            Positioned(
              top: 130,
              left: 110,
              child: Image.asset(
                'assets/images/common/minepage/杯子.png',
                width: 280,
              ),
            ),
            Positioned(
              top: 400,
              child: Image.asset(
                'assets/images/common/minepage/房子.png',
                width: 250,
              ),
            ),
            Positioned(
              bottom: 1,
              left: 130,
              child: Image.asset(
                'assets/images/common/minepage/沙发.png',
                width: 250,
              ),
            ),
            Scaffold(
              backgroundColor: Colors.transparent,
              appBar: AppBar(
                automaticallyImplyLeading: false,
                elevation: 0,
                backgroundColor: Colors.transparent,
                // title: Text('s'),
                actions: [
                  InkWell(
                    onTap: () {
                      print('被点击了');
                      Navigator.pop(context);
                    },
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Icon(Icons.arrow_forward_ios),
                    ),
                  )
                ],
              ),
              body: Container(
                child: Column(
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(left: animation1.value),
                          child: Image.asset(
                              'assets/images/common/minepage/多云.png'),
                        ),
                        Spacer(),
                        Padding(
                          padding: const EdgeInsets.only(right: 30, bottom: 30),
                          child: Text(
                            year,
                            style: TextStyle(
                              fontSize: 14,
                              fontWeight: FontWeight.bold,
                              color: Color.fromRGBO(112, 112, 112, 1),
                            ),
                          ),
                        ),
                      ],
                    ),
                    //第二行文字
                    Row(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(
                              left: 35, top: 0, right: 25, bottom: 0),
                          child: Column(
                            children: [
                              Text(
                                tem + '℃',
                                style: t1,
                              ),
                              Text(
                                '温度',
                                style: t2,
                              )
                            ],
                          ),
                        ),
                        Column(
                          children: [
                            Text(
                              hum,
                              style: t1,
                            ),
                            Text(
                              '湿度',
                              style: t2,
                            )
                          ],
                        ),
                      ],
                    )
                  ],
                ),
              ),
            ),
            Positioned(
              bottom: 0,
              child: Container(
                height: 550,
                width: MediaQuery.of(context).size.width,
                decoration: new BoxDecoration(
                    color: Colors.white.withOpacity(.8),
                    borderRadius: new BorderRadius.only(
                        topLeft: Radius.circular(40.0),
                        topRight: Radius.circular(40.0))),
                // child: Expanded(child: Text('data')),
                child: Column(
                  children: [
                    SizedBox(
                      height: 32,
                    ),
                    InkWell(
                      onTap: () {
                        Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => InformationPage()));
                      },
                      child: Container(
                        width: 300,
                        child: Row(
                          children: [
                            ClipRRect(
                              borderRadius: BorderRadius.circular(32),
                              child: Image.network(
                                context.watch<Userinfomodel>().getportraiturl(),
                                width: 64,
                                height: 64,
                              ),
                            ),
                            SizedBox(
                              width: 12,
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  context.watch<Userinfomodel>().getnickname(),
                                  style: TextStyle(
                                    color: Color.fromRGBO(72, 72, 72, 1),
                                    fontSize: 20,
                                    fontWeight: FontWeight.bold,
                                  ),
                                ),
                                SizedBox(
                                  height: 4,
                                ),
                                Text(
                                  context.watch<Userinfomodel>().getauthorization(),
                                  style: TextStyle(
                                    color: Color.fromRGBO(132, 130, 130, 1),
                                    fontSize: 12,
                                    fontWeight: FontWeight.bold,
                                  ),
                                )
                              ],
                            ),
                            Spacer(),
                            Icon(Icons.more_horiz)
                          ],
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    //下部文字框
                    Container(
                      width: 300,
                      child: Text('我的购物',
                          style: TextStyle(
                            color: Color.fromRGBO(72, 72, 72, 1),
                            fontWeight: FontWeight.bold,
                          )),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    Container(
                      height: 110,
                      width: 300,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                               Navigator.of(context).push(MaterialPageRoute(builder: (context) => OrdarPage()));
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  left: 25, right: 10, top: 20),
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/订单.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '订单',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: (){
                              
                              Navigator.of(context).push(MaterialPageRoute(builder: (context) => BuycarPage()));
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  top: 20, left: 10, right: 10),
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/购物袋.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '购物车',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                               Navigator.of(context).push(MaterialPageRoute(builder: (context) => LikePage()));
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  top: 20, left: 10, right: 10),
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/星星.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '收藏',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),

                          InkWell(
                            onTap: () {
                               Navigator.of(context).push(MaterialPageRoute(builder: (context) => AddressPage()));
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  top: 20, left: 10, right: 10),
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/地址.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '地址',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                      decoration: new BoxDecoration(
                        color: Color.fromRGBO(134, 218, 249, 1),
                        borderRadius: new BorderRadius.circular((30.0)),
                      ),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    Container(
                      width: 300,
                      child: Text(
                        '更多',
                        style: TextStyle(
                          color: Color.fromRGBO(72, 72, 72, 1),
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 16,
                    ),
                    Container(
                      height: 110,
                      width: 300,
                      child: Row(
                        children: [
                          Padding(
                            padding: const EdgeInsets.only(
                                top: 20, left: 25, right: 10),
                            child: InkWell(
                              onTap: () {
                                 Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage()));
                              },
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/通知.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '关于',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          InkWell(
                            onTap: () {
                               Navigator.of(context).push(MaterialPageRoute(builder: (context) => AgreementPage()));
                            },
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  top: 20, left: 10, right: 10),
                              child: Column(
                                children: [
                                  Container(
                                    child: Center(
                                      child: Image.asset(
                                          'assets/images/common/minepage/旗子.png',width: 32,),
                                    ),
                                    height: 50,
                                    width: 50,
                                    decoration: new BoxDecoration(
                                      color: Colors.white,
                                      borderRadius:
                                          new BorderRadius.circular((50.0)),
                                    ),
                                  ),
                                  Text(
                                    '协议',
                                    style: TextStyle(
                                      color: Color.fromRGBO(72, 72, 72, 1),
                                      fontSize: 12,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                      decoration: new BoxDecoration(
                        color: Color.fromRGBO(255, 191, 231, 1),
                        borderRadius: new BorderRadius.circular((30.0)),
                      ),
                    ),
                    Spacer(),
                    Container(
                      width: 300,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => SettingPage()));
                            },
                            child: Row(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(6.0),
                                  child: Image.asset(
                                    'assets/images/common/minepage/设置.png',
                                    color: Colors.black87,
                                  ),
                                ),
                                Text(
                                  '设置',
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Color.fromRGBO(72, 72, 72, 1),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Spacer(),
                          InkWell(
                            onTap: () {
                              _launchUrl('tel:18313307882');
                            },
                            child: Row(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(6.0),
                                  child: Image.asset(
                                      'assets/images/common/minepage/联系.png'),
                                ),
                                Text(
                                  '联系客服',
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Color.fromRGBO(72, 72, 72, 1),
                                  ),
                                ),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 32,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  _launchUrl(url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}
